/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pruefzifferBerechnung;

/**
 *
 * @author 1790
 */
public class PruefzifferBerechnung {

    public static Integer berechnePruefziffer(String wert) {
        final int MODULO_6 = 6;
        final int MODULO_10 = 10;
        final int MODULO_11 = 11;

        int n = 0;
        int len = wert.length();

        for (int i = 0; i < len; i++) {
            n += Character.getNumericValue(wert.charAt(len - 1 - i)) * (2 + (i % MODULO_6));
        }
        int pz = (MODULO_11 - (n % MODULO_11)) % MODULO_10;

        return Integer.valueOf(pz);
    }

    public Boolean istPruefzifferModulo11Gueltig(String nummerAlsString) {
        if (nummerAlsString == null) {
            return Boolean.FALSE;
        }

        int pz = nummerAlsString.charAt(nummerAlsString.length() - 1) - '0';

        int nPZ = PruefzifferBerechnung.berechnePruefziffer(nummerAlsString.substring(0, nummerAlsString.length() - 1));

        return pz == nPZ;
    }

    public static void main(String[] args) {
        String s = "12345678";
        String fullString;
        PruefzifferBerechnung pb = new PruefzifferBerechnung();
        for (int i = 0; i < 10; i++) {
            fullString = s + String.valueOf(i);
            System.out.println(s + "/" + fullString + "/" + pb.istPruefzifferModulo11Gueltig(fullString));
        }

    }

}
